﻿using System;
using System.Configuration.Install;
using System.IO;
using Microsoft.Win32;

namespace ItemTemplateInstaller
{
	public abstract class InstallerBase : Installer
	{
		protected abstract string EXEName { get; }
		protected abstract string ProductRegistryKey { get; }
		protected abstract string ProductVersion { get; }
		
		protected string DevEnvLocation
		{
			get { return Path.Combine(InstallDir, EXEName); }
		}

		protected string InstallDir
		{
			get
			{
				if (Environment.Is64BitOperatingSystem)
				{
					var dir = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\" + ProductRegistryKey + "\\" + ProductVersion, "InstallDir", string.Empty);

					if (dir != null)
						return dir.ToString();
				}
				else
				{
					var dir = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\" + ProductRegistryKey + "\\" + ProductVersion, "InstallDir", string.Empty);

					if (dir != null)
						return dir.ToString();
				}

				return string.Empty;
			}
		}
	}
}